/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.knowledge.similarity.metrics;

import co.edu.unal.bioingenium.kbmed.knowledge.hierarchy.HierarchyService;
import co.edu.unal.bioingenium.kbmed.knowledge.similarity.InformationContentService;

/**
 *
 * sim (p1,p2)= IC(LCS(p1,p2))/(IC(p1)+IC(p2)-IC(LCS(p1,p2)))
 * @author Alejandro Riveros Cruz
 */
public class Jaccard implements SemanticSimilarity {

    private HierarchyService graphManager;
    private InformationContentService informationContentValues;

    /**
     * 
     */
    public Jaccard() {
        this.graphManager = HierarchyService.getInstance();
        informationContentValues = InformationContentService.getInstance();
    }

    /**
     * 
     * @param conceptId1
     * @param conceptId2
     * @param category
     * @return
     */
    @Override
    public float getSimilarity(String conceptId1, String conceptId2, String category) {
        String lcs = graphManager.getLeastCommonSubsummer(conceptId1, conceptId2, category);
        return (2 * informationContentValues.getInformationContentValue(category, lcs)) / (informationContentValues.getInformationContentValue(category, conceptId1)
                + informationContentValues.getInformationContentValue(category, conceptId2)
                - informationContentValues.getInformationContentValue(category, lcs));
    }
}
